package ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fy.fyzf.R;
import com.fy.fyzf.base.BaseFragment;
import com.fy.fyzf.bean.ExChangeRecordBean;
import com.fy.fyzf.bean.ExchangeBean;
import com.fy.fyzf.bean.ExchangeDetailBean;
import com.fy.fyzf.bean.IntegralRecordBean;
import com.fy.fyzf.bean.IntegralStoreBean;
import com.fy.fyzf.bean.RulesBean;
import com.fy.fyzf.presenter.IntergralPresenter;
import com.fy.fyzf.view.IntergralCallBack;
import com.fy.fyzf.view.SpacesItemDecoration;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

import java.util.List;

import butterknife.BindView;
import ui.activity.ConfirmOrderActivity;
import ui.adapter.IntegralAdapter;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link IntegralStoreFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class IntegralStoreFragment extends BaseFragment<IntergralPresenter> implements IntergralCallBack {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.recycleView)
    RecyclerView recycleView;
    @BindView(R.id.smartRefresh)
    SmartRefreshLayout smartRefresh;

    // TODO: Rename and change types of parameters
    private String mParam1;
    private IntegralAdapter integralAdapter;

    public IntegralStoreFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @return A new instance of fragment IntegralStoreFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static IntegralStoreFragment newInstance(String param1) {
        IntegralStoreFragment fragment = new IntegralStoreFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
        }
    }

    @Override
    protected IntergralPresenter createPresenter() {
        return new IntergralPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_integral_store2;
    }

    @Override
    public void initView(View rootView) {
        super.initView(rootView);
        integralAdapter = new IntegralAdapter();
        recycleView.setLayoutManager(new GridLayoutManager(getActivity(),3));
        recycleView.addItemDecoration(new SpacesItemDecoration(20));
        recycleView.setAdapter(integralAdapter);

        integralAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                List<IntegralStoreBean.ListBean> data = adapter.getData();
                Intent intent = new Intent(getActivity(), ConfirmOrderActivity.class);
                intent.putExtra("data", data.get(position));
                startActivity(intent);
            }
        });
    }

    @Override
    protected void loadData() {
            mPresenter.getIntegralList(1,10,Integer.parseInt(mParam1));
    }

    @Override
    public void getIntegralListSuccess(IntegralStoreBean integralStoreBean) {
        integralAdapter.setNewData(integralStoreBean.getList());
    }

    @Override
    public void exchangeSuccess(ExchangeBean exchangeBean) {

    }

    @Override
    public void getExchangeDetailSuccess(ExchangeDetailBean exchangeDetailBean) {

    }

    @Override
    public void getExchangeRecordSuccess(ExChangeRecordBean exChangeRecordBean) {

    }

    @Override
    public void getIntegralRecordListSuccess(IntegralRecordBean integralRecordBean) {

    }

    @Override
    public void getRulesSuccess(List<RulesBean> list) {

    }
}